package function

object Function01 {
  def main(args: Array[String]): Unit = {
    println(getRes(10, 20, '+'))
    test(4)
    println("斐波那契"+fibon(7))
  }

  //定义函数
  def getRes(n1: Int, n2: Int, oper: Char) = {
    if (oper == '+') n1 + n2
    else if (oper == '-') n1 - n2
    else null
  }

  def test(n: Int) {
    if (n > 2) {
      test(n - 1)
    }
    println("n=" + n)

  }
  def fibon(n:Int):Int={
    if(n==1||n==2){
      1
    }else{
      fibon(n-1)+fibon(n-2)
    }
  }
  //p58

}
